# Maintainer: Balló György <ballogyor+arch at gmail dot com>
# Contributor: Bartłomiej Piotrowski <bpiotrowski@archlinux.org>
# Contributor: Angel Velasquez <angvp@archlinux.org>
# Contributor: Juergen Hoetzel <juergen@archlinux.org>

pkgbase=lxsession
pkgname=(lxsession lxsession-gtk3)
pkgver=0.5.5
pkgrel=1
epoch=1
pkgdesc='Lightweight X11 session manager'
arch=('loong64' 'x86_64')
url="https://lxde.org/"
license=('GPL2')
depends=('gtk2' 'gtk3' 'polkit')
makedepends=('intltool' 'docbook-xsl' 'vala')
conflicts=('lxpolkit')
source=(https://downloads.sourceforge.net/lxde/$pkgbase-$pkgver.tar.xz)
sha256sums=('e43e0d9c033095559ab57c8821c2b84fea58009d267db1324d32dca8bd4dbb46')

prepare() {
  cd $pkgbase-$pkgver

  # Regenerate C sources from Vala code
  rm *.stamp
  autoreconf -fi
}

build() {
  # GTK+ 2 version
  [ -d gtk2 ] || cp -r $pkgbase-$pkgver gtk2
  cd gtk2
  ./configure --sysconfdir=/etc --prefix=/usr --libexecdir=/usr/lib
  make

  cd "$srcdir"
  # GTK+ 3 version
  [ -d gtk3 ] || cp -r $pkgbase-$pkgver gtk3
  cd gtk3
  ./configure --sysconfdir=/etc --prefix=/usr --libexecdir=/usr/lib --enable-gtk3
  make
}

package_lxsession() {
  groups=('lxde')
  depends=('gtk2' 'polkit')
  replaces=('lxpolkit')

  cd gtk2
  make DESTDIR="$pkgdir" install
}

package_lxsession-gtk3() {
  groups=('lxde-gtk3')
  pkgdesc+=' (GTK+ 3 version)'
  depends=('gtk3' 'polkit')
  conflicts+=('lxsession')

  cd gtk3
  make DESTDIR="$pkgdir" install

  # Ignore package by AppStream to avoid duplicated IDs
  echo 'X-AppStream-Ignore=true' >> "$pkgdir/usr/share/applications/lxsession-default-apps.desktop"
  echo 'X-AppStream-Ignore=true' >> "$pkgdir/usr/share/applications/lxsession-edit.desktop"
}
